<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:th="http://www.thymeleaf.org"
	xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<!-- 引入 Bootstrap -->
<link href="/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="/css/bootstrap.css" />
<title></title>
</head>
<body>
	<table class="table table-hover">
		<thead>
			<th>服务名</th>
			<th>url</th>
			<th>状态</th>
			<th>评分</th>
			<th>更新时间</th>
			<th>添加时间</th>
			<th>操作</th>
		</thead>
		<tbody>
			<tr th:each="server : ${servers}">
				<td th:text="${server.serverName}">Onions</td>
				<td th:text="${server.url}">2.41</td>
				<td th:text="${server.getStatusStr()}">yes</td>
				<td th:text="${server.score}">yes</td>
				<td th:text="${server.updateDate}">yes</td>
				<td th:text="${server.addDate}">yes</td>
				<td>
				<input th:if="${server.status != -2}" th:data-id="${server.id}" type="button" class="btn btn-danger" value="强制下线" onclick="forceOffline(this)">
				<input th:if="${server.status == -2}" th:data-id="${server.id}" type="button" class="btn btn-primary" value="重置状态" onclick="reset(this)">
				</td>
			</tr>
		</tbody>
	</table>
	<script type="text/javascript" src="/js/jquery-1.9.1.js"></script>
	<script type="text/javascript" src="/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="/js/bootbox.js"></script>
	<script type="text/javascript">
		function forceOffline(o){
			var $this = $(o);
			var id = $this.data("id");
			var postData = {};
			postData.id = id;
			$.post("/manage/server/status/forceoffline", postData, function(result){
				if(result.code == 200){
					bootbox.alert("强制下线成功", function(){
						location.reload();
					});
					
				}else{
					bootbox.alert(result.mes);
				}
			})
		}
		
		//重置状态
		function reset(o){
			var $this = $(o);
			var id = $this.data("id");
			var postData = {};
			postData.id = id;
			$.post("/manage/server/status/reset", postData, function(result){
				if(result.code == 200){
					bootbox.alert("重置成功", function(){
						location.reload();
					});
					
				}else{
					bootbox.alert(result.mes);
				}
			})
		}
	</script>
</body>

</html>